App.Reserves.Model.Reserve = Backbone.Model.extend({
	
	urlRoot: App.Utils.getProperty('serverURL')+"reserves/",
	
	//Default values
    defaults: {
		id : null,
		numPeople : 0,
		date : new Date(),
		store : null
    },
    
    //Constructor of the model
    initialize:function () {
    	this.validators();
		App.Utils.changeDate(this,'date');
    	this.bind("change:date", function(){
    		App.Utils.changeDate(this,'date');
        });
    	this.bind("change:date-year", function(){
    		App.Utils.setDate(this,'date');
        });
    	this.bind("change:date-month", function(){
    		App.Utils.setDate(this,'date');
        });
    	this.bind("change:date-day", function(){
    		App.Utils.setDate(this,'date');
        });
    },
    
    //Removes unused attributes on the server
    prepareModel:function(){
    	this.unset("date-year",{"silent":true});
        this.unset("date-month",{"silent":true});
        this.unset("date-day",{"silent":true});
        this.unset("date-format",{"silent":true});
    },
    
    //Define the field validators
    validators: function(){
        this.validators = {};
    	this.validators.numPeople = function (value) {
            if (value == null)
            	return {isValid: false, message: "You must enter a valid numPeople"};
            else
            	return {isValid: true}; 
        };

    	this.validators.date = function (value) {
            if (value == null)
            	return {isValid: false, message: "You must enter a valid date"};
            else
            	return {isValid: true}; 
        };

    	this.validators.store = function (value) {
            if (value == null || value == '')
            	return {isValid: false, message: "You must select a store"};
            else
            	return {isValid: true};
        };

    }
});
